<?php

//此文件为主页使用到的函数
//首页显示右边的栏目,判断是否登录
function index_show_right()
{
  if (is_login())
  {
    index_show_myhome();
  }
  else 
  {
   // echo '没有登录用户';
    index_show_login();
  }
}

//显示首页主角元素
function show_hero()
{
	$html=<<<ZZZ

<div class="hero-unit">
  <h2>教室占用管理系统</h2>
  <p class="right">--湖南科技大学</p>
  <p class="right">
    <a class="btn btn-primary btn-large" href="show_news.php?id=8">
      了解更多
    </a>
  </p>
</div>

ZZZ;
	echo $html;
	nn();
}


function index_show_login()
{
  if (isset($_GET['tips']))
    $tips=$_GET['tips'];
  else $tips='你尚未登录!';
  @$user=$_GET['user'];
  $tips=htmlspecialchars($tips);
  $user=htmlspecialchars($user);
$html=<<<ZZZ

<div class='well'>
  <form class="form-horizontal" action="login.php" method="post">
    <h2>{$tips}</h2>　　　
    
    <div class="control-group">
    <label class="control-label" for="inputEmail">学号</label>
    
      <div class="controls">
        <input type="text" id="inputEmail" name="user" value='$user' autofocus="autofocus" />
      </div>
    </div>
    
    <div class="control-group">
       <label class="control-label" for="inputPassword">密码</label>
      <div class="controls">
         <!-- <label class="checkbox"><input type="checkbox" name='remember'/>记住我的密码</label>  -->
        <input type="password" id="inputPassword" name='password' />
      </div>
    </div>
    
    <div class="control-group">
      <div class="controls">
         <button type="submit" class="btn">登录</button>
         <a class="btn" href="register.php">注册</a>
         <a class="btn" href="lostpassword.php">找回密码</a>
      </div>
    </div>

  </form>
</div>

ZZZ;
echo $html;
}

function index_show_myhome()
{
  //var_dump($_SESSION);
  if ($_SESSION['email'])  $email = $_SESSION['email'];
  else $email='';
  $default = "";
  $size = 80;
  $grav_url = "http://www.gravatar.com/avatar/" . md5( strtolower( trim( "978750903@qq.com" ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;

  $qx='你的权限:';
  if ($_SESSION['permission']=='admin') $qx.='<a href="admin.php">管理全校的用户</a>';
  elseif ($_SESSION['permission']=='manager') $qx.='<a href="admin.php">管理全班的用户</a>';
  elseif ($_SESSION['permission']=='user') $qx.='申请教室';
  elseif ($_SESSION['permission']=='guest') $qx.='无,请在个人资料中申请权限';
  echo<<<ZZZ

<div class="hero-unit">

  <h1><img src="{$grav_url}" alt="" />{$_SESSION['realname']}</h1>
  <p>你的身份是{$_SESSION['permission']}</p>
  <p>{$qx}</p>
  <p>
    <a href="home.php" class="btn btn-primary btn-large">个人资料</a>
    <a href="exit.php" class="btn btn-inverse btn-large">退出登录</a>
  </p>
</div>

ZZZ;

}


?>

